package demo.android.com.mvpdemo.mvp3;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;
import android.widget.TextView;

import demo.android.com.mvpdemo.R;
import demo.android.com.mvpdemo.mvp3.base.BaseMvpActivity;
import demo.android.com.mvpdemo.mvp3.inject.InjectPresenter;
import demo.android.com.mvpdemo.retrofit.UserInfo;

public class MainActivity extends BaseMvpActivity implements UserInfoContract.UserInfoView{
    private TextView mText;
    private FrameLayout mContainer;
    //使用注入的方法来创建Presenter
    @InjectPresenter
    public UserInfoPresenter mPresenter;



    @Override
    public void onLoading() {
        //显示加载进度条
    }

    @Override
    public void onError() {

    }

    @Override
    public void onSucceed(UserInfo userInfo) {
        mText.setText(userInfo.toString());
    }

    @Override
    protected void setViewContent() {
        setContentView(R.layout.activity_main);
        mText = (TextView) findViewById(R.id.tv_text);
        mContainer = (FrameLayout) findViewById(R.id.fl_container);
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();

        transaction.replace(R.id.fl_container,new FirstFragment());
        transaction.commit();
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        // 耗时操作
        mPresenter.getUsers("ed6b0f7f34dd8cf7b003e40691457175");
    }

//    @Override
//    protected UserInfoPresenter createPresenter() {
//        return new UserInfoPresenter();
//    }
}
